<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class InsterInitData extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:InsterInitData';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '初始化数据集合';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $this->insterData();
        return 0;
    }

    //写入初始数据
    private function insterData($max = 33)
    {
        $list = [];
        for ($a = 1; $a <= $max - 5; $a++) { //第一个球
            for ($b = $a + 1; $b <= $max - 4; $b++) { //第二个球
                for ($c = $b + 1; $c <= $max - 3; $c++) { //第三个球
                    for ($d = $c + 1; $d <= $max - 2; $d++) { //第四个球
                        for ($e = $d + 1; $e <= $max - 1; $e++) { //第五个球
                            for ($f = $e + 1; $f <= $max; $f++) { //第六个球
                                $str =  sprintf("%02s", $a) . sprintf("%02s", $b) . sprintf("%02s", $c);
                                $str .= sprintf("%02s", $d) . sprintf("%02s", $e) . sprintf("%02s", $f);
                                $data['red_one']    = $a;
                                $data['red_two']    = $b;
                                $data['red_three']  = $c;
                                $data['red_four']   = $d;
                                $data['red_five']   = $e;
                                $data['red_six']    = $f;
                                $data['red_no']     = $str;
                                $data['odd_num']    = $a%2 + $b%2 + $c%2 + $d%2 + $e%2 + $f%2;
                                $data['max_cont']   = maxCont([$a,$b,$c,$d,$e,$f]);
                                $list[] = $data;
                            }
                        }
                    }
                }
            }
        }

        foreach (array_chunk($list, 5000) as $items) {
            DB::table('gather')->insert($items);
        }
    }
}
